package com.xiaoma.tpo.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiaoma.tpo.dao.TRoleRightDao;
import com.xiaoma.tpo.domain.TRoleRight;
import com.xiaoma.tpo.dto.RoleRightVO;

@Service
public class TRoleRightService {

	@Autowired
	private TRoleRightDao roleRightDao;
	

	public List<TRoleRight> getRoleRightById(Integer id) {
		TRoleRight roleRight = new TRoleRight();
		roleRight.setRoleId(id);
		List<TRoleRight> lRoleRights = roleRightDao.findByColumns(roleRight);
		return lRoleRights;
		
	}

	public void saveRoleRight(RoleRightVO roleRightVO) {
		//添加权限之前 先把所有属于次用户的权限删除掉
		roleRightDao.deleteBefore(roleRightVO.getRoleId());
		List<Integer> rightIds = roleRightVO.getRightIds();
		for(int i = 0 ;i<rightIds.size();i++){
			TRoleRight roleRight = new TRoleRight();
			roleRight.setRoleId(roleRightVO.getRoleId());
			roleRight.setRightId(rightIds.get(i));
			roleRightDao.insert(roleRight);
		}
	}
}
